<?php
$objXajax->registerFunction("frmreportpay_load");
//$objXajax->registerFunction("frmreportpay_init");
$objXajax->registerFunction("frmreportpay_productDetail");
//  
// function  frmreportpay_init(){
//     $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax      
//   $fromdate = SYSTEM_DATE;  
//   $todate = SYSTEM_DATE; 
//    $objResponse->addScript("$('#frmreportpay_fromdate').val('$fromdate')"); 
//    $objResponse->addScript("$('#frmreportpay_todate').val('$todate')");     
//     return $objResponse->getXML(); // dong luon luon co khi goi ham ajax           
// }

function frmreportpay_load($dateFrom='',$dateTo=''){     

    global $lang,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $lang ='vi';
    $datasum = array();
    $arrData = frmreportpay_createArray($datasum,$dateFrom,$dateTo);
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/main_reportpay_grid.html');
    $oTbs->MergeBlock('blk_data', $arrData); 
    $oTbs->MergeBlock('blk_data_sum', $datasum); 
    $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('frmreportpay_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmreportpay_tbl');");  
    $objResponse->addScript('changeWaiting(1);');                      
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function frmreportpay_createArray(&$datasum,$dateFrom,$dateTo){
    global $objDbUpdate;
    $hotel_id = $_SESSION['current']['hotel_id'];
    $tbl_postfix = $_SESSION['current']['tbl_postfix'];
    
    $dateFrom = $dateFrom==''?SYSTEM_DATE_START  : $dateFrom;
    $dateTo = $dateTo==''?SYSTEM_DATE  : $dateTo;
    
    $sql = " select p.*, u.username  from tbl_pay as p join tbl_user as u ON u.id = p.user_created
     where p.hotel_id = $hotel_id and datediff('$dateFrom',p.date_created)<=0 and datediff('$dateTo',p.date_created)>=0 ";//
     $arr = $objDbUpdate->GetArray($sql);
     $count = count($arr);
     $totalsum = 0;
     for($i=0;$i<$count;$i++){      
          $totalsum  += (int)$arr[$i]['money'] ;
     }          
    $datasum[0]['money']= $totalsum;
    return  $arr  ;
} 

//function frmreportpay_productDetail($generate_id){
//    global $objDbUpdate,$lang;
//    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
//    $tbl_postfix = $_SESSION['current']['tbl_postfix'];
//    $sql = " select name as productname,num as num,price as price from tbl_history_product$tbl_postfix where generate_id = '$generate_id'  ";//
   // echo $sql; die();
//     $arr = $objDbUpdate->GetArray($sql);
//     $count = count($arr);
//     $pricesum = 0;
//     for($i=0;$i<$count;$i++){
//          $pricesum  += (int)$arr[$i]['price'] ;
//     }
//     $datasum[0]['price']= $pricesum;
//    $oTbs = new clsTinyButStrong();
//    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/main_reportpay_productdetail_grid.html');
//    $oTbs->MergeBlock('blk_data', $arr); 
//    $oTbs->MergeBlock('blk_data_sum', $datasum); 
//    $oTbs->Show(TBS_NOTHING);  
//    $objResponse->addAssign('frmreportpay_productDetail', 'innerHTML', $oTbs->Source);
//    $objResponse->addScript("$('#frmreportpay_productDetail').dialog('open');");
//    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax             
//    
//} 

# end region process data
?>
